/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.nicmodule.services;

import org.testis.data.TestStepDataObject;
import org.testis.data.parser.AtofModuleParameterNames;
import org.testis.nicmodule.core.NetworkInterfaceController;
import org.testis.nicmodule.core.NetworkInterfaceControllerFactory;
import org.testis.nicmodule.data.NicModuleDataObject;
import org.testis.services.AtofModuleService;
import org.testis.services.AtofModuleTask;


/**
 *
 * @author root
 */
public class NicModuleTask extends AtofModuleTask
{

    public NicModuleTask(TestStepDataObject dataObj,
                         AtofModuleService service)
    {
        super(dataObj,
              service);

    }


    @Override
    public void afterExecute()
    {
        try {
            NicModuleDataObject dataObj = (NicModuleDataObject) m_service.
                getDataObj();
            NetworkInterfaceController controller =
                NetworkInterfaceControllerFactory.createInstance(
                dataObj.getParamModule(),
                dataObj.getParamInterface());
            String iface = dataObj.getParamInterface();
            try {
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_OUTPUT_IP,
                    controller.getNetworkOs().getIp(iface));
            } catch (Exception ex) {
            }
            try {
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_OUTPUT_SUBNET,
                    controller.getNetworkOs().getSubnetMask(iface));
            } catch (Exception ex) {
            }
            try {
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_OUTPUT_DNS,
                    controller.getNetworkOs().getDns(iface));
            } catch (Exception ex) {
            }
            try {
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_OUTPUT_GATEWAY,
                    controller.getNetworkOs().getGateway(iface));
            } catch (Exception ex) {
            }
            try {

                String macAddress = controller.getNetworkOs().getMacAddress(iface);
                String tireli = macAddress.replace(":",
                                                   "-");
                String noktali = tireli.replace("-",
                                                ":");
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_MAC_ADDRESS,
                    tireli);
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_MAC_ADDRESS_DOTTED,
                    noktali);

            } catch (Exception ex) {
            }
            try {
                m_result.getReturnValueList().put(
                    AtofModuleParameterNames.NIC_OUTPUT_ENABILITY,
                    ((Boolean) controller.getNetworkOs().isEnabled(iface)).
                    toString());
            } catch (Exception ex) {
            }

        } catch (Exception ex) {
        }
        super.afterExecute();
    }
}
